# ！ /usr/bin/python3
# -*- coding:utf-8 -*-
# @Author:Peng Cao
# @File: 03img_thresh.py
# @Software: PyCharm
import cv2.cv2 as cv
import matplotlib.pyplot as plt
import numpy as np

img = cv.imread('./data/cat.jpg', cv.IMREAD_GRAYSCALE)
# ret, dst = cv.threshold(img, 127, 255, cv.THRESH_BINARY)  # 大于阈值部分取maxval的值，小于等于取0
# ret, dst = cv.threshold(img, 127, 255, cv.THRESH_BINARY_INV)  # 小于阈值部分取maxval的值，小于等于取0
# ret, dst = cv.threshold(img, 127, 255, cv.THRESH_TRUNC)  #大于阈值的部分设为阈值，否则不变
# ret, dst = cv.threshold(img, 127, 255, cv.THRESH_TOZERO)  # 大于阈值的部分不改变，小于等于取0
ret, dst = cv.threshold(img, 130, 255, cv.THRESH_TOZERO_INV)  # 小于阈值的部分不改变，大于等于取0
print(ret,dst)
cv.imshow("阈值", dst)
cv.waitKey(0)
cv.destroyAllWindows()
